/**
 * 运营管理编辑员工
 */
import './index.less'
import tem from './index.html'
import $_fn from '~plugins'
class editstaffCtrl {
  constructor($scope,$rootScope,http,$ui) {
  	  console.log($scope.params)
      $scope.cancel = function () {
          $rootScope.$uiDirectiveModal.close() //关闭方法
      }
      //初始化对象
      $scope.param1={//接参
      	
      }
      $scope.param2={//提交传参
      }
      $scope.param3={//用户信息请求提交传参
      	id:JSON.parse($scope.params).id
      }
      console.log($('.dropdown-menu'))
  	  //用户信息请求
  	  $scope.xinXi=function(){
  	  	http.post('toEditUser.do',$scope.param3,function (data) {
				if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'succeed',
						appendTo:'.editstaff'
					})
					$scope.$apply(function(){
						$scope.param1.deptList=data.data.deptList;
						$scope.param1.positionList=data.data.positionList;
						$scope.param1.roles=data.data.roles;
						$scope.param1.admin=data.data.admin;
						$scope.param1.roleid=data.data.roleid;
						//$scope.param1.admin.did=data.data.admin.did;
						//console.log("did--------",$scope.param1.admin.did);
					})
					/*setTimeout(function(){
						
						$scope.$apply()
					},1000)*/
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.editstaff'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      	})
  	  }
  	  
  	  $scope.xinXi()
  	  
  	//添加管理员提交
  	  $scope.tiJiao1=function(){
	  	  	$scope.param2.id=$scope.param3.id;
	  	  	$scope.param2.did=$scope.param1.admin.did;
	  	  	$scope.param2.realName=$scope.param1.admin.realName;
	  	  	$scope.param2.telephone=$scope.param1.admin.telephone;
	  	  	$scope.param2.roleid=$scope.param1.roleid;
	  	  	$scope.param2.positionId=$scope.param1.admin.position_id;
	  	  	$scope.param2.mail=$scope.param1.admin.mail;
  	  		http.post('editUser.do',$scope.param2,function (data) {
				if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'succeed'
					})
					$scope.cancel()
          			$rootScope.genXin1="2";
			       // window.history.go(0)
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.editstaff'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      	})
  	  }
  }
}
editstaffCtrl.$inject = ['$scope','$rootScope','http','$ui']
module.exports = angular.module('directive.editstaff', []).directive('editstaff', function() {
    return {
        template: tem,
        replace:true,
        controller: editstaffCtrl,
        scope:{
        	params:"@"
        }
    }
}).name